package Thread;

public class Demo17 {
    private static int cnt = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            Thread curr=Thread.currentThread();
            for (int i=0;i<10000;i++){
                synchronized(curr){
                    cnt++;
                }
            }
        });
        Thread t2=new Thread(()->{
            Thread curr=Thread.currentThread();   //curr指的是当前线程，两个synchronized中的线程不同，不能触发锁
            for (int i=0;i<10000;i++){
                synchronized(curr){
                    cnt++;
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(cnt);
    }
}
